#include "src/core/file.h" // for File
#include "src/core/logging.h" // for Debug, FatalMsg, Warning
-#define MYNAME "Google Takeout"
-#define TIMELINE_OBJECTS "timelineObjects"
-static const QList<QString> takeout_month_names{
- "JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY",
- "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER"
-};
-
-static void takeout_fatal(const QString& message) {
+void GoogleTakeoutFormat::takeout_fatal(const QString& message) {
fatal(FatalMsg() << MYNAME << ": " << message);
}
-static void takeout_warning(const QString& message) {
+void GoogleTakeoutFormat::takeout_warning(const QString& message) {
Warning() << MYNAME << ": " << message;
}
/* create a waypoint from late7/lone7 and optional metadata */
-static Waypoint* takeout_waypoint(
+Waypoint* GoogleTakeoutFormat::takeout_waypoint(
int lat_e7,
int lon_e7,
const QString* shortname,
return waypoint;
}
-static bool track_maybe_add_wpt(route_head* route, Waypoint* waypoint) {
+bool GoogleTakeoutFormat::track_maybe_add_wpt(route_head* route, Waypoint* waypoint) {
if (waypoint->latitude == 0 && waypoint->longitude == 0) {
if (global_opts.debug_level >= 2) {
Debug(2) << "Track " << route->rte_name << "@" <<
return true;
}
-static QList<QJsonObject> readJson(
+QList<QJsonObject> GoogleTakeoutFormat::GoogleTakeoutInputStream::readJson(
const QString& source)
{
if (global_opts.debug_level >= 2) {
return timeline;
}
-static QList<QString> readDir(
+QList<QString> GoogleTakeoutFormat::GoogleTakeoutInputStream::readDir(
const QString& source)
{
if (global_opts.debug_level >= 2) {
* folders
*/
if (baseName.length() == 4 && baseName.toInt() > 0) {
+ static const QList<QString> takeout_month_names{
+ "JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY",
+ "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER"
+ };
for (auto&& month : takeout_month_names) {
const QString path = source + "/" + baseName + "_" + month + ".json";
const QFileInfo info{path};
* TODO: do something with simplifiedRawPath
*/
int n_points = 0;
- Waypoint* waypoint = nullptr;
auto* route = new route_head;
const QJsonObject startLoc = activitySegment[START_LOCATION].toObject();
const QJsonObject endLoc = activitySegment[END_LOCATION].toObject();
track_add_head(route);
QString timestamp;
timestamp = activitySegment[DURATION][START_TIMESTAMP].toString();
- waypoint = takeout_waypoint(
+ Waypoint* waypoint = takeout_waypoint(
startLoc[LOCATION_LATE7].toInt(),
startLoc[LOCATION_LONE7].toInt(),
nullptr, nullptr,
return n_points;
}
-void GoogleTakeoutInputStream::loadSource(const QString& source) {
+void GoogleTakeoutFormat::GoogleTakeoutInputStream::loadSource(const QString& source) {
const QFileInfo info{source};
if (info.isDir()) {
sources += readDir(source);
}
}
-QJsonValue GoogleTakeoutInputStream::next() {
+QJsonValue GoogleTakeoutFormat::GoogleTakeoutInputStream::next() {
if (!timelineObjects.isEmpty()) {
QJsonValue nextObject = timelineObjects.first();
timelineObjects.removeFirst();
#include <QJsonValue> // for QJsonValue
#include <QList> // for QList
#include <QString> // for QString
-#include <QStringLiteral> // for qMakeStringPrivate, QStringLiteral
#include <QVector> // for QVector
#include "defs.h"
*
* TODO: Allow date ranges
*/
-class GoogleTakeoutInputStream
-{
-public:
- /* Special Member Functions */
- GoogleTakeoutInputStream() = default;
- GoogleTakeoutInputStream(const QString& source) : sources({source}) {}
-
- /* Member Functions */
-
- // Returns the next timelineObject, or a null QJsonValue if we're at the end
- QJsonValue next();
-
-private:
- /* Member Functions */
-
- void loadSource(const QString& source);
-
- /* Data Members */
-
- QList<QString> sources;
- QList<QJsonObject> timelineObjects;
-};
-
/* Read-only Google Timeline Location History gpsbabel Format */
class GoogleTakeoutFormat : public Format
{
ff_type get_type() const override
{
- return ff_type_file;
+ return ff_type_file;
}
QVector<ff_cap> get_cap() const override
private:
/* Constants */
- const QString PLACE_VISIT = QStringLiteral("placeVisit");
- const QString ACTIVITY_SEGMENT = QStringLiteral("activitySegment");
- const QString ACTIVITY_TYPE = QStringLiteral("activityType");
- const QString LOCATION = QStringLiteral("location");
- const QString LOCATION_LATE7 = QStringLiteral("latitudeE7");
- const QString LOCATION_LONE7 = QStringLiteral("longitudeE7");
- const QString NAME = QStringLiteral("name");
- const QString ADDRESS = QStringLiteral("address");
- const QString DURATION = QStringLiteral("duration");
- const QString START_TIMESTAMP = QStringLiteral("startTimestamp");
- const QString START_LOCATION = QStringLiteral("startLocation");
- const QString END_TIMESTAMP = QStringLiteral("endTimestamp");
- const QString END_LOCATION = QStringLiteral("endLocation");
- const QString TIMESTAMP = QStringLiteral("timestamp");
- const QString SIMPLE_PATH = QStringLiteral("simplifiedRawPath");
- const QString POINTS = QStringLiteral("points");
- const QString WAYPOINT_PATH = QStringLiteral("waypointPath");
- const QString WAYPOINTS = QStringLiteral("waypoints");
- // for some reason that probably only a former Google engineer knows,);
- // we use = QStringLiteral("latE7"/"lngE7" here instead of "latitudeE7"/"longitudeE7".);
- // +10 points for brevity, but -100 points for inconsistency.);
- const QString LATE7 = QStringLiteral("latE7");
- const QString LONE7 = QStringLiteral("lngE7");
+ static constexpr char MYNAME[] = "Google Takeout";
+ static constexpr char TIMELINE_OBJECTS[] = "timelineObjects";
+ static constexpr char16_t PLACE_VISIT[] = u"placeVisit";
+ static constexpr char16_t ACTIVITY_SEGMENT[] = u"activitySegment";
+ static constexpr char16_t ACTIVITY_TYPE[] = u"activityType";
+ static constexpr char16_t LOCATION[] = u"location";
+ static constexpr char16_t LOCATION_LATE7[] = u"latitudeE7";
+ static constexpr char16_t LOCATION_LONE7[] = u"longitudeE7";
+ static constexpr char16_t NAME[] = u"name";
+ static constexpr char16_t ADDRESS[] = u"address";
+ static constexpr char16_t DURATION[] = u"duration";
+ static constexpr char16_t START_TIMESTAMP[] = u"startTimestamp";
+ static constexpr char16_t START_LOCATION[] = u"startLocation";
+ static constexpr char16_t END_TIMESTAMP[] = u"endTimestamp";
+ static constexpr char16_t END_LOCATION[] = u"endLocation";
+ static constexpr char16_t TIMESTAMP[] = u"timestamp";
+ static constexpr char16_t SIMPLE_PATH[] = u"simplifiedRawPath";
+ static constexpr char16_t POINTS[] = u"points";
+ static constexpr char16_t WAYPOINT_PATH[] = u"waypointPath";
+ static constexpr char16_t WAYPOINTS [] = u"waypoints";
+ // for some reason that probably only a former Google engineer knows,;
+ // we use[] = u"latE7"/"lngE7" here instead of "latitudeE7"/"longitudeE7".;
+ // +10 points for brevity, but -100 points for inconsistency.;
+ static constexpr char16_t LATE7[] = u"latE7";
+ static constexpr char16_t LONE7[] = u"lngE7";
+
+ /* Types */
+
+ class GoogleTakeoutInputStream
+ {
+ public:
+ /* Special Member Functions */
+ GoogleTakeoutInputStream() = default;
+ GoogleTakeoutInputStream(const QString& source) : sources({source}) {}
+
+ /* Member Functions */
- /* Member Functions */
+ // Returns the next timelineObject, or a null QJsonValue if we're at the end
+ QJsonValue next();
+
+ private:
+ /* Member Functions */
+ static QList<QJsonObject> readJson(const QString& source);
+ static QList<QString> readDir(const QString& source);
+ void loadSource(const QString& source);
+
+ /* Data Members */
+
+ QList<QString> sources;
+ QList<QJsonObject> timelineObjects;
+ };
+
+ /* Member Functions */
+
+ static void takeout_fatal(const QString& message);
+ static void takeout_warning(const QString& message);
+ Waypoint* takeout_waypoint(int lat_e7, int lon_e7, const QString* shortname, const QString* description, const QString* start_str);
+ static bool track_maybe_add_wpt(route_head* route, Waypoint* waypoint);
+ static void title_case(QString& title);
void add_place_visit(const QJsonObject& placeVisit);
int add_activity_segment(const QJsonObject& activitySegment);
- static void title_case(QString& title);
/* Data Members */